home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Here is an implementation of truncate/ftruncate for the MiNTlib. There
- is a special case for truncate, if the filesystem does not recognize
- FTRUNCATE and the length is zero, Fcreate is used to truncate the
- file. This only works for tosfs if the file isn't already open. The
- rest is quite straight forward.
-
- Andreas.
-
- Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
-
- */
-
- #include <compiler.h>
- #include <limits.h>
- #include <errno.h>
- #include <mintbind.h>
- #include <ioctl.h>
- #ifdef __TURBOC__
- #include <sys\types.h>
- #else
- #include <sys/types.h>
- #endif
- #include "lib.h"
-
- extern int __mint;
-
- int
- truncate (_filename, length)
- const char *_filename;
- off_t length;
- {
- int fh, res;
- char filename[PATH_MAX];
-
- (void) _unx2dos (_filename, filename);
- res = -EINVAL;
- if (__mint > 92)
- {
- res = Dcntl(FTRUNCATE, (long) filename, (long) &length);
- if (res != -EINVAL)
- {
- errno = (int) -res;
- return -1;
- }
- }
- fh = (int)Fopen (filename, 2);
- if (fh < 0)
- {
- errno = -fh;
- return -1;
- }
- if (__mint > 90)
- res = (int) Fcntl (fh, (long) &length, FTRUNCATE);
- Fclose (fh);
- if (res == -EINVAL && length == 0)
- {
- res = (int)Fcreate (filename, 0);
- if (res >= 0)
- Fclose (res);
- }
- if (res < 0)
- {
- errno = -res;
- return -1;
- }
- return 0;
- }
-
- int
- ftruncate (fd, length)
- int fd;
- off_t length;
- {
- int res;
-
- if (__mint > 90)
- res = (int) Fcntl (fd, (long) &length, FTRUNCATE);
- else
- res = -EINVAL;
-
- if (res < 0)
- {
- errno = -res;
- return -1;
- }
- return 0;
- }
-